using System;
using System.Collections.Generic;
using SharedObjects;

namespace TheGameDatabaseTool
{
	public partial class DatabaseMainScript
	{
		private ComputerSystemFeature _csfFileView;
		private ComputerSystemFeature _csfLogView;
		private ComputerSystemFeature _csfChat;
		private ComputerSystemFeature _csfEmail;
		private ComputerSystemFeature _csfPublicInfo;
		private ComputerSystemFeature _csfMarket;
		private ComputerSystemFeature _csfBanking;
		private ComputerSystemFeature _csfDatabase;
		private ComputerSystemFeature _csfLan;
		private ComputerSystemFeature _csfAccounts;
		private ComputerSystemFeature _csfUsenet;
		private ComputerSystemFeature _csfMissions;

		private SecuritySystem _ssUsernamePassword;			//SL1
		private SecuritySystem _ssFingerprintAuthentication; //SL2
		private SecuritySystem _ssRetinalScan;				//SL3
		private SecuritySystem _ssPsec;						//SL4
		private SecuritySystem _ssDna;						//SL5
		private SecuritySystem _ssTbpa;						//SL6

		//SL 0 = no security, SL1 = username/password, SL2 = UnamePwd/FPrint, SL3 += RScan, SL4 += PSEC, SL5 += DNA
		private ComputerSystem _socialSecurityDb; //Level 2
		private ComputerSystem _passportDb;		 //Level 3
		private ComputerSystem _medicalRecordsDb; //Level 4
		private ComputerSystem _securityClearanceDb; //Level 5

		private byte _classA = 0x02;
		private byte _classB = 0x02;
		private byte _classC = 0x01;

		public void CreatePrerequisiteSystems()
		{
			Corporation govCorp = GetEntity<Corporation>(new Guid("FC67C8A3-0935-4FDE-8795-E98171C4F2B9").ToLong());
			govCorp.Name = "Government IT Infrastructure";
			govCorp.TopLevelDomain = GetEntity<Tld>(new Guid("E207E334-24E9-484C-BFA5-042A3501C9A7").ToLong());

			#region Create Social Security DB system, for .FPRINT files

			NetworkAddress ssdbNwa = CreateNetworkAddress(new Guid("BB6DC16C-C4B6-49F3-8AA3-67B3B6A40EE1").ToLong(), 0x02, 0x01, 0x01, 0x01);
			PointD pos = _coordinator.GetFreeRandomGridpoint(govCorp.Id);
			_socialSecurityDb = GetEntity<ComputerSystem>(new Guid("59104319-019C-4AB5-B3D9-86854A9BBADB").ToLong());
			_socialSecurityDb.ComputerSystemFeatures = _socialSecurityDb.ComputerSystemFeatures ?? new List<ComputerSystemFeature> {_csfEmail, _csfChat, _csfFileView, _csfLogView, _csfDatabase};
			_socialSecurityDb.Name = "Social Security Database";
			_socialSecurityDb.Corporation = _socialSecurityDb.Corporation ?? govCorp;
			_socialSecurityDb.ComputerSystemLogs = _socialSecurityDb.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			_socialSecurityDb.MapX = _socialSecurityDb.MapX == 0 ? pos.X : _socialSecurityDb.MapX;
			_socialSecurityDb.MapY = _socialSecurityDb.MapY == 0 ? pos.Y : _socialSecurityDb.MapY;
			_socialSecurityDb.MaintenanceInterval = 20d/2;
			_socialSecurityDb.DifficultyLevel = 2;
			_socialSecurityDb.SecuritySystem = _socialSecurityDb.SecuritySystem ?? new List<SecuritySystem> {_ssUsernamePassword, _ssFingerprintAuthentication};
			_socialSecurityDb.Accounts = _socialSecurityDb.Accounts ?? new List<ComputerSystemAccount> {CreateAdminAccount(2, govCorp)};
			_socialSecurityDb.NetworkAddress = _socialSecurityDb.NetworkAddress ?? ssdbNwa;
			_socialSecurityDb.RootDirectory = _socialSecurityDb.RootDirectory ?? new SystemDirectory { Id = Guid.NewGuid().ToLong() };
			_socialSecurityDb.AlwaysVisible = false;
			#endregion

			#region Create Passport and ID DB for .RSCAN files

			pos = _coordinator.GetFreeRandomGridpoint(Guid.Empty.ToLong());
			NetworkAddress ppdbNwa = CreateNetworkAddress(new Guid("94C64389-869B-47BD-8C64-3C18DA621754").ToLong(), 0x02, 0x01, 0x01, 0x02);
			_passportDb = GetEntity<ComputerSystem>(new Guid("DB7A8226-D3A1-4D53-87B1-616F5C61B0FE").ToLong());
			_passportDb.ComputerSystemFeatures = _passportDb.ComputerSystemFeatures ?? new List<ComputerSystemFeature> {_csfEmail, _csfChat, _csfFileView, _csfLogView, _csfDatabase};
			_passportDb.Name = "Global Identity Administration Database";
			_passportDb.Corporation = _passportDb.Corporation ?? govCorp;
			_passportDb.ComputerSystemLogs = _passportDb.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			_passportDb.MapX = _passportDb.MapX == 0 ? pos.X : _passportDb.MapX;
			_passportDb.MapY = _passportDb.MapY == 0 ? pos.Y : _passportDb.MapY;
			_passportDb.MaintenanceInterval = 20d/3;
			_passportDb.DifficultyLevel = 3;
			_passportDb.SecuritySystem = _passportDb.SecuritySystem ?? new List<SecuritySystem> {_ssUsernamePassword, _ssFingerprintAuthentication, _ssRetinalScan};
			_passportDb.Accounts = _passportDb.Accounts ?? new List<ComputerSystemAccount> {CreateAdminAccount(3, govCorp)};
			_passportDb.NetworkAddress = _passportDb.NetworkAddress ?? ppdbNwa;
			_passportDb.RootDirectory = _passportDb.RootDirectory ?? new SystemDirectory { Id = Guid.NewGuid().ToLong()};
			_passportDb.AlwaysVisible = true;
			#endregion

			#region Create Medical DB system, for .DNA files

			pos = _coordinator.GetFreeRandomGridpoint(Guid.Empty.ToLong());
			NetworkAddress mrdbNwa = CreateNetworkAddress(new Guid("59F7A2C6-4310-40A0-8F1A-FAF32EAE0729").ToLong(), 0x02, 0x01, 0x01, 0x03);
			_medicalRecordsDb = GetEntity<ComputerSystem>(new Guid("A6803583-90D6-45B2-A242-874081015FEC").ToLong());
			_medicalRecordsDb.ComputerSystemFeatures = _medicalRecordsDb.ComputerSystemFeatures ?? new List<ComputerSystemFeature> {_csfEmail, _csfChat, _csfFileView, _csfLogView, _csfDatabase};
			_medicalRecordsDb.Name = "Global Medical Records Database";
			_medicalRecordsDb.Corporation = _medicalRecordsDb.Corporation ?? govCorp;
			_medicalRecordsDb.ComputerSystemLogs = _medicalRecordsDb.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			_medicalRecordsDb.MapX = _medicalRecordsDb.MapX == 0 ? pos.X : _medicalRecordsDb.MapX;
			_medicalRecordsDb.MapY = _medicalRecordsDb.MapY == 0 ? pos.Y : _medicalRecordsDb.MapY;
			_medicalRecordsDb.MaintenanceInterval = 20d/4;
			_medicalRecordsDb.DifficultyLevel = 4;
			_medicalRecordsDb.SecuritySystem = _medicalRecordsDb.SecuritySystem ?? new List<SecuritySystem> {_ssUsernamePassword, _ssFingerprintAuthentication, _ssRetinalScan, _ssDna};
			_medicalRecordsDb.Accounts = _medicalRecordsDb.Accounts ?? new List<ComputerSystemAccount> {CreateAdminAccount(4, govCorp)};
			_medicalRecordsDb.NetworkAddress = _medicalRecordsDb.NetworkAddress ?? mrdbNwa;
			_medicalRecordsDb.RootDirectory = _medicalRecordsDb.RootDirectory ?? new SystemDirectory { Id = Guid.NewGuid().ToLong()};
			_medicalRecordsDb.AlwaysVisible = true;
			#endregion

			#region Create Security Clearance DB for .PSEC files
			pos = _coordinator.GetFreeRandomGridpoint(0);
			NetworkAddress scdbNwa = CreateNetworkAddress(new Guid("64B11139-B441-44E1-8707-BDE2F247A9A3").ToLong(), 0x02, 0x01, 0x01, 0x04);
			_securityClearanceDb = GetEntity<ComputerSystem>(new Guid("A66B3F4B-48C8-4CA5-9130-5D6FE30AC535").ToLong());
			_securityClearanceDb.ComputerSystemFeatures = _securityClearanceDb.ComputerSystemFeatures ?? new List<ComputerSystemFeature> {_csfEmail, _csfChat, _csfFileView, _csfLogView, _csfDatabase};
			_securityClearanceDb.Name = "Global Security Clearance Records Database";
			_securityClearanceDb.Corporation = _securityClearanceDb.Corporation ?? govCorp;
			_securityClearanceDb.ComputerSystemLogs = _securityClearanceDb.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			_securityClearanceDb.MapX = _securityClearanceDb.MapX == 0 ? pos.X : _securityClearanceDb.MapX;
			_securityClearanceDb.MapY = _securityClearanceDb.MapY == 0 ? pos.Y : _securityClearanceDb.MapY;
			_securityClearanceDb.MaintenanceInterval = 20d / 5;
			_securityClearanceDb.DifficultyLevel = 5;
			_securityClearanceDb.SecuritySystem = _securityClearanceDb.SecuritySystem ?? new List<SecuritySystem> { _ssUsernamePassword, _ssFingerprintAuthentication, _ssRetinalScan, _ssDna, _ssPsec };
			_securityClearanceDb.Accounts = _securityClearanceDb.Accounts ?? new List<ComputerSystemAccount> { CreateAdminAccount(5, govCorp) };
			_securityClearanceDb.NetworkAddress = _securityClearanceDb.NetworkAddress ?? scdbNwa;
			_securityClearanceDb.RootDirectory = _securityClearanceDb.RootDirectory ?? new SystemDirectory { Id = Guid.NewGuid().ToLong() };
			_securityClearanceDb.AlwaysVisible = true;
			#endregion
			
			Db.PersistEntity(_socialSecurityDb);
			Db.PersistEntity(_passportDb);
			Db.PersistEntity(_medicalRecordsDb);
			Db.PersistEntity(_securityClearanceDb);
		}

		private int _numCorpsDone;
		/// <summary>
		/// Creates all corporation's computer systems, using a difficulty modifier.
		/// </summary>
		/// <param name="corp"></param>
		public void CreateCompanySystems(Corporation corp)
		{
			Random rand = new Random(Environment.TickCount);
			int difficulty = corp.DifficultyModifier;
			_numCorpsDone++;
			_classA++;
			if (_classA == 255)
			{
				_classA = 0x03;
				_classB = 0x02;
			}
			_classC = (byte) rand.Next(128, 255);
			byte classD = 0x01;
			//in total, all SecSystems will be used. Thus we need at least 1 account + credentials that applies to all 5 systems.
			//this can be compared to some sort of ActiveDirectory authentication, where 1 account gets access to N systems.

			//create database CSs for Fingerprint/Retinal Scan/DNA files (copies)
			//with every created credentialfile, a copy must be placed in the respective database CS file system.

			#region Create credential data for corp's global admin(s)
			string hostname = "admin." + corp.Name + "." + corp.TopLevelDomain.Name;
			List<ComputerSystemAccount> adminAccounts = new List<ComputerSystemAccount>();
			//rest see below
			#endregion

			#region Create SecLevel 0 system: Public Services, no security, only one system feature: Public Information
			PointD sl0Position = _coordinator.GetFreeRandomGridpoint(corp.Id);
			ComputerSystem sl0 = GetEntity<ComputerSystem>(_corporationIdToComputersystemId[corp.Id][0].ToLong());
			sl0.ComputerSystemFeatures = sl0.ComputerSystemFeatures ?? new List<ComputerSystemFeature> {_csfPublicInfo};
			sl0.Name = "Public Service";
			sl0.Corporation = sl0.Corporation ?? corp;
			sl0.ComputerSystemLogs = sl0.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			sl0.MapX = sl0.MapX == 0 ? sl0Position.X : sl0.MapX;
			sl0.MapY = sl0.MapY == 0 ? sl0Position.Y : sl0.MapY;
			sl0.SecuritySystem = sl0.SecuritySystem ?? new List<SecuritySystem>();
			sl0.Accounts = sl0.Accounts ?? new List<ComputerSystemAccount>();
			sl0.MaintenanceInterval = 0;
			sl0.DifficultyLevel = 0;
			sl0.NetworkAddress = sl0.NetworkAddress ?? new NetworkAddress {ClassA = _classA, ClassB = _classB, ClassC = _classC, ClassD = classD++, Id = Guid.NewGuid().ToLong()};
			sl0.RootDirectory = null;
			sl0.AlwaysVisible = true;
			Db.PersistEntity(sl0);

			#endregion

			#region Create SecLevel 1 system: Internal Services, usernamepassword, fingerprint
			PointD sl1Position = _coordinator.GetFreeRandomGridpoint(corp.Id);
			ComputerSystem sl1 = GetEntity<ComputerSystem>(_corporationIdToComputersystemId[corp.Id][1].ToLong());
			sl1.ComputerSystemFeatures = sl1.ComputerSystemFeatures ?? new List<ComputerSystemFeature> {_csfEmail, _csfChat, _csfUsenet, _csfFileView, _csfLogView, _csfMarket, _csfAccounts};
			sl1.Name = "Internal Services";
			sl1.Corporation = sl1.Corporation ?? corp;
			sl1.ComputerSystemLogs = sl1.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			sl1.MapX = sl1.MapX == 0 ? sl1Position.X : sl1.MapX;
			sl1.MapY = sl1.MapY == 0 ? sl1Position.Y : sl1.MapY;
			sl1.MaintenanceInterval = 20d;
			sl1.DifficultyLevel = 1 + difficulty;
			sl1.IsDefaultEmailServer = true;
			sl1.SecuritySystem = sl1.SecuritySystem ?? new List<SecuritySystem> {_ssUsernamePassword, _ssFingerprintAuthentication};
			
			//if there's no account set defined for the system, it's a fresh run, thus we create it (meaning that all slXXX.Accounts will be null).
			//this is moved here to skip creating an account set when not necessary.
			if(sl1.Accounts == null)
			{
				for (int i = 0; i < 3; i++)
				{
					string userName = GenerateRandomName();
					string password = GenerateRandomPassword(16).EncryptPassword();
					ComputerSystemAccount account = new ComputerSystemAccount
					{
						Id = Guid.NewGuid().ToLong(),
						CreationTime = DateTime.Now,
						IsDefault = true,
						IsTemporary = false,
						Username = userName,
						Credentials = new List<Credential>()
					};
					Credential credUpc;
					_ssUsernamePassword.CreateCredentials(userName, password, hostname, out credUpc);
					account.Credentials.Add(credUpc);

					Credential credFPrint;
					_ssFingerprintAuthentication.CreateCredentials(userName, password, hostname, out credFPrint);
					account.Credentials.Add(credFPrint);

					Credential credRscan;
					_ssRetinalScan.CreateCredentials(userName, password, hostname, out credRscan);
					account.Credentials.Add(credRscan);

					Credential credDna;
					_ssDna.CreateCredentials(userName, password, hostname, out credDna);
					account.Credentials.Add(credDna);

					Credential credPsec;
					_ssPsec.CreateCredentials(userName, password, hostname, out credPsec);
					account.Credentials.Add(credPsec);

					//we dont create tbpa credentials for admins, since tbpa is pvp only
					//Credential credTBPA;
					//ssTBPA.CreateCredentials(userName, password, hostname, out credTBPA);
					//account.Credentials.Add(credTBPA);
					adminAccounts.Add(account);
					//db.PersistEntity(account);
				}
			}
			sl1.Accounts = sl1.Accounts ?? new List<ComputerSystemAccount>(adminAccounts);
			sl1.NetworkAddress = sl1.NetworkAddress ?? new NetworkAddress {ClassA = _classA, ClassB = _classB, ClassC = _classC, ClassD = classD++, Id = Guid.NewGuid().ToLong()};
			sl1.RootDirectory = sl1.RootDirectory ?? new SystemDirectory {Id = Guid.NewGuid().ToLong()};
			Db.PersistEntity(sl1);

			BankAccount sl1Bank = GetSystemBankAccount(sl1.Id);
			Db.PersistEntity(sl1Bank);
			#endregion

			#region Create SecLevel 2 system: Finances, usernamepassword, fingerprint, retinal
			PointD sl2Position = _coordinator.GetFreeRandomGridpoint(corp.Id);
			ComputerSystem sl2 = GetEntity<ComputerSystem>(_corporationIdToComputersystemId[corp.Id][2].ToLong());
			sl2.ComputerSystemFeatures = sl2.ComputerSystemFeatures ?? new List<ComputerSystemFeature> { _csfEmail, _csfChat, _csfFileView, _csfLogView, _csfBanking, _csfAccounts };
			sl2.Name = "Financial Services";
			sl2.Corporation = sl2.Corporation ?? corp;
			sl2.ComputerSystemLogs = sl2.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			sl2.MapX = sl2.MapX == 0 ? sl2Position.X : sl2.MapX;
			sl2.MapY = sl2.MapY == 0 ? sl2Position.Y : sl2.MapY;
			sl2.MaintenanceInterval = 15d;
			sl2.DifficultyLevel = 2 + difficulty;
			sl2.TrustedConnectionOnly = true;
			sl2.IsDefaultBankServer = true;
			sl2.SecuritySystem = sl2.SecuritySystem ?? new List<SecuritySystem> { _ssUsernamePassword, _ssFingerprintAuthentication, _ssRetinalScan };
			sl2.Accounts = sl2.Accounts ?? new List<ComputerSystemAccount>(adminAccounts);
			sl2.NetworkAddress = sl2.NetworkAddress ?? new NetworkAddress {ClassA = _classA, ClassB = _classB, ClassC = _classC, ClassD = classD++, Id = Guid.NewGuid().ToLong()};
			sl2.RootDirectory = sl2.RootDirectory ?? new SystemDirectory {Id = Guid.NewGuid().ToLong()};
			Db.PersistEntity(sl2);

			BankAccount sl2Bank = GetSystemBankAccount(sl2.Id);
			Db.PersistEntity(sl2Bank);
			#endregion

			#region Create SecLevel 3 system: Mainframe, usernamepassword, fingerprint, retinal, dna

			PointD sl3Position = _coordinator.GetFreeRandomGridpoint(corp.Id);
			ComputerSystem sl3 = GetEntity<ComputerSystem>(_corporationIdToComputersystemId[corp.Id][3].ToLong());
			sl3.ComputerSystemFeatures = sl3.ComputerSystemFeatures ?? new List<ComputerSystemFeature> { _csfEmail, _csfChat, _csfFileView, _csfLogView, _csfMarket, _csfAccounts };
			sl3.Name = "Computing Center";
			sl3.Corporation = sl3.Corporation ?? corp;
			sl3.ComputerSystemLogs = sl3.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			sl3.MapX = sl3.MapX == 0 ? sl3Position.X : sl3.MapX;
			sl3.MapY = sl3.MapY == 0 ? sl3Position.Y : sl3.MapY;
			sl3.MaintenanceInterval = 10d;
			sl3.DifficultyLevel = 3 + difficulty;
			sl3.TrustedConnectionOnly = true;
			sl3.SecuritySystem = sl3.SecuritySystem ?? new List<SecuritySystem> { _ssUsernamePassword, _ssFingerprintAuthentication, _ssRetinalScan, _ssDna };
			sl3.Accounts = sl3.Accounts ?? new List<ComputerSystemAccount>(adminAccounts);
			sl3.NetworkAddress = sl3.NetworkAddress ?? new NetworkAddress {ClassA = _classA, ClassB = _classB, ClassC = _classC, ClassD = classD++, Id = Guid.NewGuid().ToLong()};
			sl3.RootDirectory = sl3.RootDirectory ?? new SystemDirectory {Id = Guid.NewGuid().ToLong()};

			Db.PersistEntity(sl3);

			BankAccount sl3Bank = GetSystemBankAccount(sl3.Id);
			Db.PersistEntity(sl3Bank);
			#endregion

			#region Create SecLevel 4 system: Corporation Gateway, usernamepassword, fingerprint, retinal, dna, psec

			PointD sl4Position = _coordinator.GetFreeRandomGridpoint(corp.Id);
			ComputerSystem sl4 = GetEntity<ComputerSystem>(_corporationIdToComputersystemId[corp.Id][4].ToLong());
			sl4.ComputerSystemFeatures = new List<ComputerSystemFeature> { _csfEmail, _csfChat, _csfFileView, _csfLogView, _csfLan, _csfAccounts };
			sl4.Name = "External Gateway";
			sl4.Corporation = sl4.Corporation ?? corp;
			sl4.ComputerSystemLogs = sl4.ComputerSystemLogs ?? new List<ComputerSystemLog>();
			sl4.MapX = sl4.MapX == 0 ? sl4Position.X : sl4.MapX;
			sl4.MapY = sl4.MapY == 0 ? sl4Position.Y : sl4.MapY;
			sl4.MaintenanceInterval = 5d;
			sl4.DifficultyLevel = 4 + difficulty;
			sl4.TrustedConnectionOnly = true;
			sl4.SecuritySystem = sl4.SecuritySystem ?? new List<SecuritySystem> {_ssUsernamePassword, _ssFingerprintAuthentication, _ssRetinalScan, _ssDna, _ssPsec };
			sl4.Accounts = sl4.Accounts ?? new List<ComputerSystemAccount>(adminAccounts);
			sl4.NetworkAddress = sl4.NetworkAddress ?? new NetworkAddress {ClassA = _classA, ClassB = _classB, ClassC = _classC, ClassD = classD, Id = Guid.NewGuid().ToLong()};
			sl4.RootDirectory = sl4.RootDirectory ?? new SystemDirectory {Id = Guid.NewGuid().ToLong()};
			sl4.IsGatewayCentral = true;

			//this doesn't make sense. TBPA files will be stored on sl4, but that's player accounts only.
			//foreach (ComputerSystemAccount a in adminAccounts)
			//{
			//    foreach (TbpaCredential fc in a.Credentials.OfType<TbpaCredential>())
			//    {
			//        SystemFile f = fc.GetCredentialFileCopy();
			//        sl4.RootDirectory.Files.Add(f);
			//    }
			//}
			Db.PersistEntity(sl4);

			#endregion

			#region Create SecLevel 5 system: player gateway, usernamepassword, fingerprint, retinal, dna, psec, tbpa
			#endregion

			Db.Deactivate(adminAccounts, 2);
		}

		private ComputerSystemAccount CreateAdminAccount(int difficulty, Corporation corp)
		{
			string userName = GenerateRandomName();
			string password = GenerateRandomPassword(16).EncryptPassword();
			string adminhost = string.Format("admin.{0}.{1}", corp.Name, corp.TopLevelDomain.Name);

			ComputerSystemAccount account = new ComputerSystemAccount
			{
				Id = Guid.NewGuid().ToLong(),
				CreationTime = DateTime.Now,
				IsDefault = true,
				IsTemporary = false,
				Username = userName,
				Credentials = new List<Credential>()
			};
			//create 5 credentials and store the credentialfiles in the appropriate databases.
			Credential credUpc;
			_ssUsernamePassword.CreateCredentials(userName, password, adminhost, out credUpc);
			account.Credentials.Add(credUpc);

			if (difficulty > 1)
			{
				Credential credFPrint;
				_ssFingerprintAuthentication.CreateCredentials(userName, password, adminhost, out credFPrint);
				account.Credentials.Add(credFPrint);
			}

			if (difficulty > 2)
			{
				Credential credRscan;
				_ssRetinalScan.CreateCredentials(userName, password, adminhost, out credRscan);
				account.Credentials.Add(credRscan);
			}

			if (difficulty > 3)
			{
				Credential credPsec;
				_ssPsec.CreateCredentials(userName, password, adminhost, out credPsec);
				account.Credentials.Add(credPsec);
			}

			if (difficulty > 4)
			{
				Credential credDna;
				_ssDna.CreateCredentials(userName, password, adminhost, out credDna);
				account.Credentials.Add(credDna);
			}
			return account;
		}

	}
}